package com.qiaofang.applet.rest;

import com.qiaofang.applet.common.dto.DataRequest;
import com.qiaofang.applet.common.dto.DataResponse;
import com.qiaofang.applet.service.member.service.EmployeePropertyService;
import com.qiaofang.applet.service.member.service.dto.EmployeePropertyBatchSaveDto;
import com.qiaofang.applet.service.member.service.dto.EmployeePropertySaveDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/web/auth/employee")
@Api(tags = "经纪人：经纪人操作模块")
public class EmployeeOpController {

    @Autowired
    private EmployeePropertyService employeePropertyService;


    @PostMapping("/addProperty")
    @ApiOperation(value = "经纪人添加房源", notes = "经纪人添加房源")
    public DataResponse<Object> addProperty(@RequestBody @Valid DataRequest<EmployeePropertySaveDto> request) {

        employeePropertyService.saveByParams(request.getParam());

        return DataResponse.ok();
    }

    @PostMapping("/addPropertyBatch")
    @ApiOperation(value = "经纪人批量添加房源", notes = "经纪人批量添加房源")
    public DataResponse<Object> addPropertyBatch(@RequestBody @Valid DataRequest<EmployeePropertyBatchSaveDto> request) {

        employeePropertyService.batchSaveByParams(request.getParam());

        return DataResponse.ok();
    }

    @PostMapping("/removeProperty")
    @ApiOperation(value = "经纪人移除房源", notes = "经纪人移除房源")
    public DataResponse<Object> removeProperty(@RequestBody @Valid DataRequest<EmployeePropertySaveDto> request) {

        employeePropertyService.removeByParams(request.getParam());

        return DataResponse.ok();
    }

    @PostMapping("/getOpFlag")
    @ApiOperation(value = "详情页经纪人添加移除标识", notes = "详情页经纪人添加移除标识")
    public DataResponse<String> getOpFlag(@RequestBody @Valid DataRequest<EmployeePropertySaveDto> request) {
        return DataResponse.ok(employeePropertyService.getOpFlag(request.getParam()));
    }
}
